package com.zhiyou.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zhiyou.model.FyMyCommission;
import com.zhiyou.service.CommissionService;
import com.zhiyou.utils.JsonResult;

@RestController		//代表下面所有的mapping都是返回json的
@RequestMapping("commission/")
public class CommissionController {
	
	@Autowired
	CommissionService service;
	
	//查询全部
	@GetMapping(value="list")
	public JsonResult show(HttpServletRequest req, HttpServletResponse resp){
		return new JsonResult(200, service.selectall(), "查询成功！");
		
	}
	
	//添加代办
	@PostMapping("add/")
	public JsonResult add(FyMyCommission commission,HttpServletRequest req, HttpServletResponse resp){
		service.add(commission);
		return new JsonResult(200, "添加成功！！");
	}
	
	//删除待办
	@DeleteMapping("delete/{commission_id}")
	public JsonResult delete(@PathVariable("commission_id")Integer commission_id,HttpServletRequest req, HttpServletResponse resp){
		service.delete(commission_id);
		return new JsonResult(200,"删除成功！！");
		
	}
	
	//根据id查询
	@GetMapping("selectByid/{commission_id}")
	public JsonResult selectByid(@PathVariable("commission_id")Integer commission_id,HttpServletRequest req, HttpServletResponse resp){
		System.out.println(commission_id);
		return new JsonResult(200, service.selectByid(commission_id), "查询成功！！");
		
	}
	
	//全部标为已读
	@GetMapping("readed/")
	public JsonResult readed(HttpServletRequest req, HttpServletResponse resp){
		service.readed();
		return new JsonResult(200,"全部标为已读！");
	}
	
	//修改
	@PutMapping("update/")
	public JsonResult update(FyMyCommission commission,HttpServletRequest req, HttpServletResponse resp){
		
		service.update(commission);
		return new JsonResult(200, "修改成功！！");
		
	}
	
}
